// pages/videoRecord/videoRecord.js
var businessLogic = require('../../../utils/NetWork/Model/VideobusinessLogic.js')
var common = require('../../../utils/common.js')

Page({

    /**
     * 页面的初始数据
     */
    data: {
      num: 1,
      scrollHeight: 0,
      video:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let c = common.Getorgid();
        var scrollHeight = scrollHeight;
        wx.getSystemInfo({
          success: function (res) {
            scrollHeight = res.windowHeight
          }
        });
        this.setData({
            orgid: c.orgid,
            userid: c.userid,
            videoid:options.videoid,
            scrollHeight: scrollHeight,
        });
        this.QueryPeVideo()
    },
    bindDownLoad: function () {
      if (this.data.lenpage > this.data.num) {
        var di = this.data.num;
        var di = di + 1;
        this.setData({
          num: di
        });
      } else {
        common.showToast("加载全部", "loading");
      }
      //common.showToast("到底了", "loading");

    },

        /**
         * 生命周期函数--监听页面初次渲染完成
         */
        onReady: function () {
        
        },

        /**
         * 生命周期函数--监听页面显示
         */
        onShow: function () {
        
        },

        /**
         * 生命周期函数--监听页面隐藏
         */
        onHide: function () {
        
        },

        /**
         * 生命周期函数--监听页面卸载
         */
        onUnload: function () {
        
        },

        /**
         * 页面相关事件处理函数--监听用户下拉动作
         */
        onPullDownRefresh: function () {
        
        },

        /**
         * 页面上拉触底事件的处理函数
         */
        onReachBottom: function () {
        
        },

        /**
         * 用户点击右上角分享
         */
        onShareAppMessage: function () {
        
        },
    //
    QueryPeVideo:function(){
      common.showToast("加载中", "loading");
      let params = { "num": 15, "page": this.data.num, "orgid": this.data.orgid, "userid": this.data.userid, searchField: "peopleid, videoid", searchValue: this.data.userid + "," + this.data.videoid }
        businessLogic.QueryPeVideo(params, (res) => {
            for (let a = 0; a < res.length; a++) {
                var x = []
                switch (res[a].type) {
                    case 1:
                        x = "考试"
                        break;
                    default:
                        x = "播放视频";
                }
                res[a].typeCN = []
                res[a].typeCN.push(x);

                //结束播放时间
                if ((res[a].etime + "").length == 13) { 
                  var end = res[a].etime;
                } else if ((res[a].etime + "").length == 10) {
                  var end = res[a].etime * 1000;
                }
                //开始播放时间
                if ((res[a].stime + "").length == 13) {
                  var start = res[a].stime;
                } else if ((res[a].stime + "").length == 10) {
                  var start = res[a].stime * 1000;
                    }
                    var date = new Date(end);
                    var dateS = new Date(start);
                    let timeO = new Date(date - Date.parse(dateS)) //时间戳差值
                    let h = Math.floor(timeO / (1000 * 60 * 60))
                    let m = Math.floor(timeO % (1000 * 60 * 60) / (1000 * 60))
                    let s = Math.floor(timeO % (1000 * 60 * 60) % (1000 * 60) / 1000)

                    if(h>0){var playedTime = h + "时" +m + "分" + s + "秒"
                    }else{var playedTime=m+"分"+s+"秒"
                    }
                    res[a].playedTime = []
                    res[a].playedTime.push(playedTime);

                //观看时间
                    var Y = date.getFullYear() + '-';
                    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();

                    var h = date.getHours() < 10 ? '0' + date.getHours() + ':': date.getHours() + ':';
                    var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();

                    var dateTime=Y+M+D
                    var startTime=h+m

                    res[a].dateTime = []
                    res[a].dateTime.push(dateTime);
                    res[a].startTime = []
                    res[a].startTime.push(startTime);
                //console.log(startTime)
            }
            /* var bbb = this.data.video;
            for (var a = 0; a < res.infos.length; a++) {
              bbb.push(res.infos[a]);
            }  */
           
            this.setData({
                video: res,
                //lenpage: res.page.pages
            });
        });
    }
})